<?php
namespace app\model;
use think\Model;

class Common extends Model
{
    protected $dateFormat = 'Y-m-d H:i:s';
    protected $autoWriteTimestamp = 'datetime';
    protected $createTime = 'create_at';
    protected $updateTime = 'update_at';


    public static function onBeforeInsert($model)
    {
        $fields = $model->getTableFields();
        if (in_array("create_uid",$fields) && session('uid')) {
            $model->create_uid =  session("uid");
        }
        if (in_array("update_uid",$fields) && session('uid')) {
            $model->update_uid =  session("uid");
        }
        if (in_array("create_operator",$fields) && session('user.username')) {
            $model->create_operator =  session("user.username");
        }
        if (in_array("update_operator",$fields) && session('user.username')) {
            $model->update_operator = session("user.username");
        }

    }

    public static function onBeforeUpdate($model)
    {
        $fields = $model->getTableFields();
        if (in_array("update_uid",$fields) && session('uid')) {
            $model->update_uid =  session("uid");
        }
        if (in_array("update_operator",$fields) && session('user.username')) {
            $model->update_operator = session("user.username");
        }
    }
}